<template>
  <div class="my-artists">
    <div class="my-artists-main">
      <div class="my-artists-hd-box">
        <h1 class="my-artists-hd">我的歌手（{{ aTotal }}）</h1>
      </div>
      <ul class="my-artists-ul">
        <li class="my-artists-item" v-for="item in artists" :key="item.id">
          <div class="my-artists-item-left">
            <a href="javascript:;" @click="clickArtist(item.id)">
              <img
                :src="item.img1v1Url"
                :alt="item.name"
                class="my-artists-item-pic"
              />
            </a>
          </div>
          <div class="my-artists-item-main">
            <div>
              <h4 class="my-artists-item-name" @click="clickArtist(item.id)">
                <a href="javascript:;">{{ item.name }}</a>
              </h4>
              <span class="my-artists-item-trans" v-if="item.trans">
                {{ item.trans }}
              </span>
            </div>
            <span class="my-artists-item-album"
              >{{ item.albumSize }}个专辑</span
            >
            <span class="my-artists-item-mv">{{ item.mvSize }}个MV</span>
          </div>
        </li>
      </ul>
    </div>
    <div class="artists-el-pagination" v-if="aTotal > 25">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage"
        :page-size="25"
        layout="prev, pager, next, jumper"
        :total="aTotal"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    aTotal: {
      type: Number,
      default() {
        return 0;
      },
    },
  },
  data() {
    return {
      artists: [],
      currentPage: 1,
    };
  },
  mounted() {
    this.getArtists();
  },
  methods: {
    clickArtist(id) {
      this.playArtistDetail(id);
    },
    handleCurrentChange() {
      // console.log(this.currentPage);
      // console.log(`当前页: ${val}`);
      this.getArtists();
      // 点击分页后，滚动到评论的头部，141为页面头部组件的高度
      this.$emit("pScroll", 0);
    },
    getArtists() {
      this.axios({
        url: "/artist/sublist?offset=" + (this.currentPage - 1) * 25,
      })
        .then((res) => {
          this.artists = res.data.data;
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style>
.my-artists {
  padding: 0 10px;
}
.my-artists .my-artists-main {
  position: relative;
}
.my-artists .my-artists-main .my-artists-hd-box {
  height: 45px;
  border-bottom: 4px solid var(--color-theme);
}
.my-artists .my-artists-main .my-artists-hd {
  display: block;
  margin: 0;
  font-size: 24px;
  font-weight: 400;
}
.my-artists .my-artists-item {
  position: relative;
  height: 100px;
  padding: 10px 0;
  overflow: hidden;
  border-bottom: 1px solid #999;
}
.my-artists-item-left {
  float: left;
  width: 80px;
  height: 80px;
  overflow: hidden;
}
.my-artists-item-left a {
  display: block;
  width: 80px;
  height: 80px;
}
.my-artists-item-left .my-artists-item-pic {
  width: 80px;
  height: 80px;
}
.my-artists-item-main {
  margin-left: 90px;
}
.my-artists-item-name {
  display: inline-block;
  height: 50px;
  line-height: 50px;
  font-size: 16px;
  font-weight: 400;
  cursor: pointer;
}
.my-artists-item-name a:hover {
  text-decoration: underline;
}
.my-artists-item-trans {
  margin-left: 5px;
  font-size: 14px;
  color: #999;
}
.my-artists-item-album,
.my-artists-item-mv {
  margin-right: 10px;
  font-size: 12px;
  color: #333;
}
.artists-el-pagination {
  position: relative;
  text-align: center;
  margin: 20px auto;
}
</style>